<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<title>设置价格提醒</title>
	<link rel="stylesheet" type="text/css" href="static/easyui/themes/metro/easyui.css">
	<link rel="stylesheet" type="text/css" href="static/easyui/themes/mobile.css">
	<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
	<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="static/easyui/jquery.easyui.mobile.js"></script>
</head>

<script>


	$(function(){
		$("#selected").combobox({
			onSelect:function(record){
				var value=$("#selected").combobox('getText');
				queryLoginUser();
				// queryPrice(value);
			}
		});
	})

	function queryLoginUser() {
		$.ajax({
			url:"queryUserEmail",
			type:"post",
			async:false,
			data:{"email":""},
			/* dataType: "json", */
			success:function(respResult){
				$("#email").textbox("setValue", respResult);
			},
			error:function(respResult){
				alert('用户未登录');
			}
		});
	}

	function queryPrice(name) {
		$.ajax({
			url:"getPrice",
			type:"post",
			async:false,
			data:{"name":name},
			/* dataType: "json", */
			success:function(respResult){
				var result =respResult[0];
				$("#down_price").textbox("setValue", result.buy_price);
				$("#up_price").textbox("setValue", result.sell_price);
				$("#down_change_margin").textbox("setValue", Math.abs(result.change_margin.substr(0,result.change_margin.indexOf("%"))));
				$("#up_change_margin").textbox("setValue", Math.abs(result.change_margin.substr(0,result.change_margin.indexOf("%"))));

			},
			error:function(respResult){
				alert('用户未登录');
			}
		});
	}


	function refesh(){
		var value=$("#selected").combobox('getText');
		queryPrice(value);
	}

	function turnToSimpleList() {
		window.location.href="simpleListhtml";
	}

	function submitForm(){
		var value = $("#selected").combobox("getText");
		var email = $("#email").combobox("getText");
		var down_price=$("#down_price").combobox('getText');
		var up_price=$("#up_price").combobox('getText');
		var down_change_margin="-"+$("#down_change_margin").combobox('getText')+"%";
		var up_change_margin=$("#up_change_margin").combobox('getText')+"%";
		$.ajax({
			url:"priceSetting",
			type:"post",
			async:false,
			data:{"name":value,"email":email, "down_price":down_price, "up_price":up_price, "down_change_margin":down_change_margin,
				"up_change_margin":up_change_margin},
			/* dataType: "json", */
			success:function(respResult){
				if("SUCCESS"==respResult){
					alert("成功");
					window.location.href="simpleListhtml";
				}else if("paramNull"==respResult){
					alert("参数不能为空");
				}else if("down_change_margin_fail"==respResult){
					alert("日跌幅超不能为正数且需要%");
				}else if("up_change_margin_fail"==respResult){
					alert("日涨幅超不能为负数且需要%");
				}
			},
			error:function(respResult){
				alert('异常回到首页');
				window.location.href="index";
			}
		});

	}

</script>


<body>
	<div class="easyui-navpanel" style="position:relative;padding:20px">
		<header>
			<div class="m-toolbar">
				<div class="m-title">设置价格提醒(客户方向)</div>
			</div>
		</header>
		<form id="ff">
			<div style="margin-bottom:10px">
				<table>
					<td> 选择货币:
						<select class="easyui-combobox" name="state"  id = "selected"  style="width:100px;">
							<option value="AGTD">AGTD</option>
							<option value="AUTD">AUTD</option>
							<option value="USDCNY">USDCNY</option>
							<option value="HKDCNY">HKDCNY</option>
							<option value="JPYCNY">JPYCNY</option>
							<option value="AUDCNY">AUDCNY</option>
							<option value="GBPCNY">GBPCNY</option>
							<option value="CHFCNY">CHFCNY</option>
						</select>
					</td>
					<td>
						<a href="#" class="easyui-linkbutton" onclick="refesh()">查询价格</a>
					</td>
				</table>

			</div>


			<div style="margin-bottom:10px">
				<input class="easyui-textbox" name="email" style="width:80%" id="email"  value="" data-options="label:'提醒邮箱:',required:true,validType:'email'">
			</div>

			<div style="margin-bottom:10px">
				<input class="easyui-textbox" label="卖价下跌到:"  id ="down_price" prompt="卖价" style="width:80%">
			</div>

			<div style="margin-bottom:10px">
				<input class="easyui-textbox" label="买价上涨到:"  id ="up_price" prompt="买价" style="width:80%">
			</div>

			<div style="margin-bottom:10px">
				<input class="easyui-textbox" label="日涨幅超:+"  id ="up_change_margin" prompt="涨跌额" style="width:80%"><span>%</span>
			</div>

			<div style="margin-bottom:10px">
				<input class="easyui-textbox" label="日跌幅超:-" id ="down_change_margin" prompt="涨跌幅" style="width:80%"><span>%</span>
			</div>
		</form>
		<div style="text-align:center;padding:5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:100%">设置</a>
		</div>
		<div style="text-align:center;padding:5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="turnToSimpleList()" style="width:100%">跳转查询页</a>
		</div>
	</div>
</body>
</html>